<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<head>
</head>
<body>
<div class="x-body">
    <form:form id="saveForm" modelAttribute="entity" cssStyle="margin-left: 20px;" cssClass="layui-form layui-form-pane">
        <div style="width:100%;height:400px;overflow: auto;">
            <input value="${entity.id}" type="hidden" name="id">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="name" class="layui-form-label"><span class="x-red">*</span>名称</label>
                    <div class="layui-input-inline">
                        <form:input path="name" cssClass="required layui-input" maxlength="50"></form:input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">是否按钮</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="isButton" id ="isButton" lay-skin="switch" lay-filter="isButton" title="是否"
                               value="${entity.isButton == null?0:entity.isButton}" <c:if test="${entity.isButton == '1'}">checked</c:if>>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="url" class="layui-form-label"><span class="x-red">*</span>url</label>
                <div class="layui-input-block">
                    <form:input path="url" cssClass="required layui-input"></form:input>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="parentResource.id" class="layui-form-label"><span class="x-red">*</span>父级</label>
                <div class="layui-input-block">
                    <%--<form:input path="parentResource.id" cssClass="layui-input"></form:input>--%>
                    <sys:treeselect  id="parentResourceId" name="parentResource.id" value="${entity.parentResource.id}"
                                    labelName="parentResource.name" labelValue="${entity.parentResource.name}"
                                 	title="父级" extId="${entity.id}"
                                    url="/sysResource/ztreeDataNoUrl" cssClass="layui-input" cssStyle="width:200px;"></sys:treeselect>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="code" class="layui-form-label"><span class="x-red">*</span>code</label>
                    <div class="layui-input-inline">
                        <form:input path="code" cssClass=" layui-input" maxlength="50"></form:input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label for="iconClass" class="layui-form-label"><span class="x-red">*</span>图标</label>
                    <div class="layui-input-inline">
                        <sys:iconselect id="iconClass" name="iconClass" value="${entity.iconClass}"/>
                       <%-- <form:input path="iconClass" cssClass="required layui-input" maxlength="50"></form:input>--%>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label for="remark" class="layui-form-label"><span class="x-red">*</span>备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" id="remark"  placeholder="请输入内容" class="layui-textarea">${entity.remark}</textarea>
                </div>
            </div>
        </div>
        <c:if test="${!detail}">
            <div style="width: 100%;height: 55px;background-color: white;border-top:1px solid #e6e6e6;
		  position: fixed;bottom: 1px;margin-left:-20px;">
                <div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">
                    <a  class="layui-btn layui-btn-normal" lay-filter="add" lay-submit>确定</a>
                    <a  class="layui-btn layui-btn-primary" id="close">取消</a>
                </div>
            </div>
        </c:if>
    </form:form>
</div>
</body>
<myfooter>
    <script type="text/javascript">
        $(document).ready(function() {
            var detail='${detail}';
            if(detail=="true"){
                $("form").disable();
            }
        });
        $('#close').click(function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
        var validate = $("#saveForm").validate();

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            form.on('switch(isButton)', function(data){
                if(data.elem.checked){
                    $("#isButton").val("1");
                }else{
                    $("#isButton").val("0");
                }
            });
            //监听提交
            form.on('submit(add)', function(data){
                if(validate.form()){
                    var indexFormSubmit = layer.load(2, {shade: [0.3, '#333']});
                    $.ajax({
                        url:'${ctx}/sysResource/saveEntity',
                        type:'post',
                        data:data.field,
                        async:false,
                        traditional: true,
                        success:function(d){
                            layer.close(indexFormSubmit);
                            if(d.flag=="200"){
                                parent.$("#refresh").trigger("click");
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.top.layer.msg(d.msg,{icon:6,offset: 'rb',area:['120px','80px'],anim:2});
                            }else{
                                window.top.layer.msg(d.msg,{icon:5,offset: 'rb',area:['120px','80px'],anim:2});
                            }
                        },error:function(){
                            layer.close(indexFormSubmit);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.top.layer.msg('请求失败',{icon:5,offset: 'rb',area:['120px','80px'],anim:2});
                        }
                    })
                }
                return false;
            });
            form.render();
        });
    </script>
</myfooter>